﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZBJF.Warranty.Common.Common;
using ZBJF.Warranty.Model;
using ZBJF.Warranty.Model.ViewModel.Config;

namespace ZBJF.Warranty.BLL
{
    public partial class AppSettingsService
    {

        public AppSettings Load(string configKey)
        {
            return LoadEntities(c => c.ConfigKey == configKey).FirstOrDefault();
        }

        public bool Update(string configKey, string configValue, string remark = "")
        {
            var entity = Load(configKey);
            entity.ConfigValue = configValue;
            entity.Remark = remark;
            CacheHelper.Instance.RemoveCache("AppConfigCache");
            return UpdateEntities(entity);
        }
        public IQueryable<AppSettings> GetPagingList(AppSettingModel model, out int total)
        {
            var predicate = PredicateExtensions.True<AppSettings>();
            if (!string.IsNullOrEmpty(model.Keyword))
            {
                predicate =
                    predicate.And(
                        w =>
                            w.ConfigKey.Contains(model.Keyword) || w.ConfigValue.Contains(model.Keyword) || w.Remark.Contains(model.Keyword));
            }
            return LoadPagerEntities<AppSettings>(model.PageIndex,
                model.iDisplayLength,
                out total, predicate, model.iSorts);
        }
    }
}
